namespace AdminSG3L.Applicaticn.Dtos;

/// <summary>
/// 访问统计查询DTO
/// </summary>
public class VisitStatsQueryDto
{
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
    public string? Granularity { get; set; } = "day"; // hour, day, week, month
    public string? Dimension { get; set; } // page, source, device, location
    public string? Filters { get; set; }
    public int Page { get; set; } = 1;
    public int PageSize { get; set; } = 20;
}

/// <summary>
/// 用户行为查询DTO
/// </summary>
public class UserBehaviorQueryDto
{
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
    public string? EventType { get; set; }
    public string? PageUrl { get; set; }
    public int Page { get; set; } = 1;
    public int PageSize { get; set; } = 50;
}

/// <summary>
/// 用户行为DTO
/// </summary>
public class UserBehaviorDto
{
    public string EventType { get; set; } = string.Empty;
    public string UserId { get; set; } = string.Empty;
    public string? PageUrl { get; set; }
    public Dictionary<string, object> Properties { get; set; } = new();
    public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}

/// <summary>
/// 留存分析查询DTO
/// </summary>
public class RetentionQueryDto
{
    public DateTime? CohortDate { get; set; }
    public string RetentionType { get; set; } = "daily"; // daily, weekly, monthly
    public int Periods { get; set; } = 30;
    public string? UserSegment { get; set; }
}

/// <summary>
/// 用户画像查询DTO
/// </summary>
public class UserPortraitQueryDto
{
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
    public List<string> Dimensions { get; set; } = new();
    public Dictionary<string, object> Filters { get; set; } = new();
    public int Page { get; set; } = 1;
    public int PageSize { get; set; } = 20;
}

/// <summary>
/// 热力图查询DTO
/// </summary>
public class HeatmapQueryDto
{
    public string? PageUrl { get; set; }
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
    public string Type { get; set; } = "click"; // click, scroll, move
}

/// <summary>
/// 事件统计查询DTO
/// </summary>
public class EventStatsQueryDto
{
    public string? EventName { get; set; }
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
    public string? GroupBy { get; set; }
    public int Page { get; set; } = 1;
    public int PageSize { get; set; } = 20;
}

/// <summary>
/// 自定义报表配置DTO
/// </summary>
public class CustomReportConfigDto
{
    public string Name { get; set; } = string.Empty;
    public string? Description { get; set; }
    public List<string> Metrics { get; set; } = new();
    public List<string> Dimensions { get; set; } = new();
    public Dictionary<string, object> Filters { get; set; } = new();
    public string? Schedule { get; set; } // cron expression
    public List<string> Recipients { get; set; } = new();
}

/// <summary>
/// 数据对比查询DTO
/// </summary>
public class ComparisonQueryDto
{
    public DateTime? Period1Start { get; set; }
    public DateTime? Period1End { get; set; }
    public DateTime? Period2Start { get; set; }
    public DateTime? Period2End { get; set; }
    public List<string> Metrics { get; set; } = new();
    public string? Dimension { get; set; }
}

/// <summary>
/// 趋势分析查询DTO
/// </summary>
public class TrendAnalysisQueryDto
{
    public string Metric { get; set; } = string.Empty;
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
    public string Granularity { get; set; } = "day";
    public string? Dimension { get; set; }
}

/// <summary>
/// 异常检测查询DTO
/// </summary>
public class AnomalyDetectionQueryDto
{
    public string Metric { get; set; } = string.Empty;
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
    public double Sensitivity { get; set; } = 0.95;
}

/// <summary>
/// 预测查询DTO
/// </summary>
public class PredictionQueryDto
{
    public string Metric { get; set; } = string.Empty;
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }
    public int ForecastDays { get; set; } = 30;
    public string Algorithm { get; set; } = "linear"; // linear, polynomial, exponential
}

/// <summary>
/// 警报配置DTO
/// </summary>
public class AlertConfigDto
{
    public string Name { get; set; } = string.Empty;
    public string? Description { get; set; }
    public string Metric { get; set; } = string.Empty;
    public string Condition { get; set; } = string.Empty; // >, <, =, >=, <=
    public double Threshold { get; set; }
    public string? TimeWindow { get; set; }
    public List<string> Recipients { get; set; } = new();
    public bool IsEnabled { get; set; } = true;
}

/// <summary>
/// 警报DTO
/// </summary>
public class AlertDto
{
    public Guid Id { get; set; }
    public required string Name { get; set; }
    public string? Description { get; set; }
    public required string Metric { get; set; }
    public required string Condition { get; set; }
    public double Threshold { get; set; }
    public string? TimeWindow { get; set; }
    public bool IsEnabled { get; set; }
    public string Status { get; set; } = "active"; // active, triggered, resolved
    public DateTime? LastTriggeredAt { get; set; }
    public DateTime? LastCheckedAt { get; set; }
    public List<string> Recipients { get; set; } = new();
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    public DateTime? UpdatedAt { get; set; }
}

/// <summary>
/// 页面性能DTO
/// </summary>
public class PagePerformanceDto
{
    public string PageUrl { get; set; } = string.Empty;
    public decimal LoadTime { get; set; }
    public decimal FirstPaint { get; set; }
    public decimal FirstContentfulPaint { get; set; }
    public decimal LargestContentfulPaint { get; set; }
    public decimal TimeToInteractive { get; set; }
    public decimal InteractionToNextPaint { get; set; }
    public decimal CumulativeLayoutShift { get; set; }
}

/// <summary>
/// 热力图点DTO
/// </summary>
public class HeatmapPointDto
{
    public double X { get; set; }
    public double Y { get; set; }
    public long Count { get; set; }
    public long ClickCount { get; set; }
    public double Intensity { get; set; }
    public string? ElementSelector { get; set; }
}

/// <summary>
/// 通用API响应DTO
/// </summary>
public class ApiResponseDto<T>
{
    public int Code { get; set; } = 200;
    public string Message { get; set; } = "Success";
    public T? Data { get; set; }
    public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}

/// <summary>
/// 通用API响应DTO (无泛型)
/// </summary>
public class ApiResponseDto
{
    public int Code { get; set; } = 200;
    public string Message { get; set; } = "Success";
    public object? Data { get; set; }
    public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}

/// <summary>
/// 分页响应DTO
/// </summary>
public class PagedResponseDto<T>
{
    public int Code { get; set; } = 200;
    public string Message { get; set; } = "Success";
    public List<T> Data { get; set; } = new();
    public int Page { get; set; }
    public int PageSize { get; set; }
    public int Total { get; set; }
    public int TotalPages => (int)Math.Ceiling((double)Total / PageSize);
    public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}

/// <summary>
/// 通用响应DTO
/// </summary>
public class ResponseDto<T>
{
    public int Code { get; set; } = 200;
    public string Message { get; set; } = "Success";
    public T? Data { get; set; }
    public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}

/// <summary>
/// 通用响应DTO (无泛型)
/// </summary>
public class ResponseDto
{
    public int Code { get; set; } = 200;
    public string Message { get; set; } = "Success";
    public object? Data { get; set; }
    public string? Error { get; set; }
    public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}